package cqut.wys.web;

import cqut.wys.entity.User;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

/**
 * @author wuyoushan@zbj.com
 * @date 2017/3/9.
 */
@RestController
@Api(value = "用户controller",tags = {"用户管理API"})
public class UserController {

    @ApiOperation(value="添加用户",notes="添加用户notes",produces ="application/json")
    @RequestMapping(value="/addUser",method= RequestMethod.POST)
    public void addUser(@ApiParam(value = "用户参数")@RequestBody User user){

    }

    @ApiOperation(value = "删除用户",notes = "删除用户notes")
    @RequestMapping(value="/removeUser",method= RequestMethod.GET)
    public void removeUser(@ApiParam(value = "用户ID")@RequestBody Integer id){

    }

    @ApiOperation(value = "查询用户",notes = "查询用户notes")
    @RequestMapping(value="/getUser",method= RequestMethod.POST)
    @ResponseBody
    @ApiResponses(value={
            @ApiResponse(code=123,message="xxx"),
            @ApiResponse(code=405,message="not found")
    })
    public User getUser(@ApiParam("用户名")String name){
        User user=new User(1L,"姓名",18,"女");
        return user;
    }

    @ApiOperation(value="更新用户信息", notes="根据url的id来指定更新对象，并根据传过来的user信息来更新用户详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User")
    })
    @RequestMapping(value="/updateUser/{id}", method=RequestMethod.POST)
    public String updateUser(@PathVariable Long id,@RequestBody User user){
        User u=new User();
        u.setId(id);
        u.setName(user.getName());
        u.setGender(user.getGender());
        u.setAge(user.getAge());
        return "success";
    }
}
